import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class WebApplication {
    public static void main(String[] args) throws Exception{
        final ZKListenerDataSource datasource = ZKListenerDataSource.create("linux121");
        getConnection(datasource);
        System.out.println("连接完成");

        while(true){
            System.in.read();
            System.out.println("开始检查");
            getConnection(datasource);
        }
    }

    private static void getConnection(ZKListenerDataSource zkListenerDataSource) throws SQLException {
        try (
                Connection connection = zkListenerDataSource.getConnection();
                ResultSet resultSet = connection.prepareStatement("select user()").executeQuery();
        ) {
            while (resultSet.next()) {
                System.out.println("当前登录的用户名:" + resultSet.getString(1));
            }
        }
    }
}
